var HashMapArray = require("../utils/HashMapArray.js");

var idNum = 0;

var designData = {
	ver: "1.0.0",
	createTime: new Date().dateFormat('yyyyMMDDHHmmss'),
	elements: new HashMapArray(),
	bg: null,
	product: null
};

/*
 * 初始化数据
 */
designData.setJson = function(data) {
	Design.event.trigger(Design.event.UPDATE_DEDSIGN_DATA, data);
}

designData.setBgElement = function(element){
	designData.bg = element;
}

/*
 * 获取保存的数据
 */
designData.getSaveData = function() {
	var d = designData;
	var json = {
		ver: d.ver,
		createTime: d.createTime,
		updateTime: new Date().dateFormat('yyyyMMDDHHmmss'),
		elements: [],
		bg: d.bg.getSaveData()
	}

	/*
	 * 获取元素数据
	 */
	for(var i = 0; i < this.elements.length; i++) {
		var ele = this.elements.getValueAt(i);
		var eledata = ele.getSaveData();
		json.elements.push(eledata);
	}

	return json;
}

exports = module.exports = designData;